<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@include file="/WEB-INF/jsp/common/head.jsp"%>

<div class="content">
    <div class="container-fluid">
        <nav class="pull-left">
            <strong>你现在所在的位置是:</strong>&nbsp;&nbsp;&nbsp;
            <span>商品管理页面</span><br><br>
        </nav>
    </div>

    <div class="container-fluid">
        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="content">
                        <!-- 搜索表单 -->
                        <form class="form-inline" method="get"
                              action="${pageContext.request.contextPath }/sys/product/list">
                            <div class="row">
                                <!-- 商品名称搜索 -->
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label for="productName">商品名称</label>
                                        <input type="text" name="productName"
                                               class="form-control border-input"
                                               value="${productName}"
                                               placeholder="请输入商品名称"
                                               id="productName">
                                    </div>
                                </div>

                                <!-- 商品分类下拉 -->
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label for="categoryLevel3Id">商品分类</label>
                                        <select class="form-control border-input"
                                                name="categoryLevel3Id"
                                                id="categoryLevel3Id">
                                            <option value="">- 全部 -</option>
                                            <c:forEach var="category" items="${categoryList}">
                                                <option value="${category.id}"
                                                        <c:if test="${category.id eq categoryLevel3Id}">selected="selected"</c:if>>
                                                        ${category.name}
                                                </option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                </div>

                                <input type="hidden" name="pageIndex" value="1"/>

                                <div class="col-md-3">
                                    <div class="text-center">
                                        <button type="submit"
                                                class="btn btn-primary btn-fill btn-wd">
                                            搜&nbsp;&nbsp;索
                                        </button>
                                    </div>
                                </div>

                                <div class="col-md-3">
                                    <div class="text-center">
                                        <a class="btn btn-danger btn-fill btn-wd"
                                           href="${pageContext.request.contextPath}/sys/product/add">
                                            添加商品
                                        </a>
                                    </div>
                                </div>
                            </div>
                            <div class="clearfix"></div>
                        </form>
                    </div>

                    <!-- 商品列表表格 -->
                    <div class="content table-responsive table-full-width">
                        <table class="table table-striped">
                            <thead>
                            <tr>
                                <th width="20%">商品名称</th>
                                <th width="15%">商品价格</th>
                                <th width="15%">商品库存</th>
                                <th width="30%">商品描述</th>
                                <th width="20%">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:forEach var="product" items="${productList}" varStatus="status">
                                <tr>
                                    <td><span>${product.name}</span></td>
                                    <td><span>${product.price}</span></td>
                                    <td><span>${product.stock}</span></td>
                                    <td><span>${product.description}</span></td>
                                    <td>
                                        <!-- 查看按钮 -->
                                        <span>
                                            <a class="btn btn-info btn-xs"
                                               href="${pageContext.request.contextPath}/sys/product/view/${product.id}">
                                                查看
                                            </a>
                                        </span>&nbsp;&nbsp;

                                        <!-- 编辑按钮 -->
                                        <span>
                                            <a class="btn btn-warning btn-xs"
                                               href="${pageContext.request.contextPath}/sys/product/modify/${product.id}">
                                                编辑
                                            </a>
                                        </span>&nbsp;&nbsp;

                                        <!-- 删除按钮 -->
                                        <span>
                                            <a class="btn btn-success btn-xs"
                                               href="${pageContext.request.contextPath}/sys/product/delete/${product.id}"
                                               onclick="return confirm('确认删除【${product.name}】吗？')">
                                                删除
                                            </a>
                                        </span>
                                    </td>
                                </tr>
                            </c:forEach>
                            </tbody>
                        </table>
                    </div>

                    <!-- 分页组件 -->
                    <div class="text-center">
                        <ul class="pagination">
                            <c:if test="${pageIndex > 1}">
                                <li>
                                    <a href="${pageContext.request.contextPath}/sys/product/list?pageIndex=1&amp;productName=${productName}&amp;categoryLevel3Id=${categoryLevel3Id}">首页</a>
                                </li>
                                <li>
                                    <a href="${pageContext.request.contextPath}/sys/product/list?pageIndex=${pageIndex-1}&amp;productName=${productName}&amp;categoryLevel3Id=${categoryLevel3Id}">上一页</a>
                                </li>
                            </c:if>

                            <c:forEach begin="1" end="${totalPageCount}" var="i">
                                <li <c:if test="${pageIndex == i}">class="active"</c:if>>
                                    <a href="${pageContext.request.contextPath}/sys/product/list?pageIndex=${i}&amp;productName=${productName}&amp;categoryLevel3Id=${categoryLevel3Id}">${i}</a>
                                </li>
                            </c:forEach>

                            <c:if test="${pageIndex < totalPageCount}">
                                <li>
                                    <a href="${pageContext.request.contextPath}/sys/product/list?pageIndex=${pageIndex+1}&amp;productName=${productName}&amp;categoryLevel3Id=${categoryLevel3Id}">下一页</a>
                                </li>
                                <li>
                                    <a href="${pageContext.request.contextPath}/sys/product/list?pageIndex=${totalPageCount}&amp;productName=${productName}&amp;categoryLevel3Id=${categoryLevel3Id}">末页</a>
                                </li>
                            </c:if>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<%@ include file="common/foot.jsp" %>

<script type="text/javascript">
    // 激活侧边栏菜单
    $(".sidebar-wrapper .nav li:eq(1)").addClass("active");
</script>